def solve():
_ = int(input())
t = input()
ctn = 0
for i in t:
if i == 'Q':
ctn += 1
else:
ctn -= 1
if ctn < 0:
ctn = 0
return "Yes" if ctn == 0 else "No"
if __name__ == "__main__":
t = int(input())
for _ in range(t):
print(solve())
//MANISHk
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define frr(i, k, n) for (int i = n - 1; i >= k; i--)
#define fr(i, k, n) for (int i = k; i < n; i++)
long long f(int a, int b) {
if(b == 0) return 1;
long long p = f(a,b/2);
if(b%2==0) return (p*p)%1000000007;
else return (((p*p)%1000000007) * a) % 1000000007;
}
ll gcd(ll a, ll b){
if (a == 0)
return b;
if (b == 0)
return a;
if (a < b)
return gcd(a, b % a);
return gcd(b, a % b);
}
ll lcm (ll a , ll b){
return (a*b) / gcd(a , b);
}
bool isperfect(double n){
if(n >= 0){
ll x = sqrt(n);
return (x*x == n);
}
else
return false;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
ll gcdExtended(ll a, ll b, ll *x, ll *y);
ll modInverse(ll b, ll m){
ll x, y;
ll g = gcdExtended(b, m, &x, &y);
if (g != 1)
return -1;
return (x%m + m) % m;
}
ll modDivide(ll a, ll b, ll m){
a = a % m;
ll inv = modInverse(b, m);
return (inv * a) % m;
}
ll gcdExtended(ll a, ll b, ll *x, ll *y){
if (a == 0){
*x = 0, *y = 1;
return b;
}
ll x1;ll y1;
ll gcd = gcdExtended(b%a, a, &x1, &y1);
*x = y1 - (b/a) * x1;
*y = x1;
return gcd;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void solve(){
ll n;
cin>>n;
string s;
cin>>s;
ll qc=0,ac=0;
for(int i=0;i<n;i++){
if(s[i]=='Q')qc++;
else qc--;
if(qc<0)qc=0;
}
if(qc!=0)cout<<"No"<<endl;
else cout<<"Yes"<<endl;
// cout<<qc<<ac<<endl;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main(){
ll t;
cin>>t;
while(t--){
solve();
}
}
432D - Prefixes and Suffixes | 486A - Calculating Function |
1373B - 01 Game | 1187A - Stickers and Toys |
313B - Ilya and Queries | 579A - Raising Bacteria |
723A - The New Year Meeting Friends | 302A - Eugeny and Array |
1638B - Odd Swap Sort | 1370C - Number Game |
1206B - Make Product Equal One | 131A - cAPS lOCK |
1635A - Min Or Sum | 474A - Keyboard |
1343A - Candies | 1343C - Alternating Subsequence |
1325A - EhAb AnD gCd | 746A - Compote |
318A - Even Odds | 550B - Preparing Olympiad |
939B - Hamster Farm | 732A - Buy a Shovel |
1220C - Substring Game in the Lesson | 452A - Eevee |
1647B - Madoka and the Elegant Gift | 1408A - Circle Coloring |
766B - Mahmoud and a Triangle | 1618C - Paint the Array |
469A - I Wanna Be the Guy | 1294A - Collecting Coins |